@extends('backend.layouts.app')

@section('content')
<div class="layui-card">
    <div class="layui-card-header layui-card-header-auto">
        导师分类列表
    </div>
    <div class="layui-card-body">
        <div class="layui-row" style="margin-bottom:10px">
            <div class="layui-col-md9">&nbsp;</div>
            <div class="layui-col-md3">
                <div class="layui-btn-group" style="float:right">
                    <a href="{{route('admin.business.mentor.category.create')}}" class="layui-btn layui-btn-sm">添加</a>
                </div>
            </div>
        </div>
        <table id="dataTable" lay-filter="dataTable">
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm" lay-event="show">查看</a>
                    <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
                </div>

            </script>
        </table>
    </div>
</div>
@endsection

@section('script')
<script type="text/javascript">
    layui.use(['layer', 'form', 'index', 'table', 'treetable'], function () {
        let layer = layui.layer;
        let form = layui.form;
        let treetable = layui.treetable;
        let table = layui.table;

        layer.load(2);
        treetable.render({
            treeColIndex: 0,
            treeSpid: '',
            treeIdName: 'id',
            treePidName: 'pid',
            elem: '#dataTable',
            url: "{{route('admin.business.mentor.category.list')}}",
            page: false,
            cols: [
                [{
                    title: 'ID',
                    width: 100,
                    field: 'id'
                }, {
                    title: '分类名称',
                    width: 150,
                    field: 'name'
                }, {
                    title: '英文标识',
                    width: 150,
                    field: 'ident'
                }, {
                    title: '状态',
                    width: 80,
                    field: 'status',
                    templet: function (res) {
                        if (res.status == 0) {
                            return '<span class="label layui-bg-green" style="padding:5px;font-size:10px">正常</span>';
                        }
                        return '<span class="label layui-bg-red" style="padding:5px;font-size:10px">停用</span>'
                    }
                }, {
                    title: '操作',
                    align: 'center',
                    toolbar: '#options'
                }]
            ],
            done: function () {
                layer.closeAll('loading');
            }
        });

        table.on('tool(dataTable)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;

            switch (layEvent) {
                case 'show':
                    location.href = 'category/' + data.id + '/show';
                    break;
                case 'edit':
                    location.href = 'category/' + data.id + '/edit';
                    break;
                case 'del':
                    layer.confirm('确认删除吗？', function (index) {
                        $.post("{{ route('admin.business.mentor.category.destroy') }}", {
                                '_method': 'delete',
                                '_token': '{{csrf_token()}}',
                                ids: data.id
                            },
                            function (result) {
                                if (result.code == 0) {
                                    obj.del(); //删除对应行（tr）的DOM结构
                                }
                                layer.close(index);
                                layer.msg(result.msg);
                            });
                    });
                    break;
                default:
                    break;
            }
        });
    });

</script>
@endsection
